﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using DMS.Business.Modules.Organization;
using DMS.Business.Utility;

namespace DMS.Web.Common.Controls
{
    public partial class TopNavigation : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void rpTopNav_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            AuthenticationUser aUser = SystemContext.Current.LoginAuthUser;
            SiteMapNode node = e.Item.DataItem as SiteMapNode;
            if (node == null)
            {
                return;
            }

            if (node.Roles.Count > 0)
            {
                bool isDisplay = false;
                foreach (string role in node.Roles)
                {
                    if (aUser.IsInRole(role))
                    {
                        isDisplay = true;
                        break;
                    }
                }

                e.Item.Visible = isDisplay;
            }
        }
    }
}